//
//  BuyNowView.m
//  夺宝吧
//
//  Created by xiaocai on 15/6/30.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "BuyNowView.h"
#import "NSString+GetSize.h"
#import "LockView.h"
@interface BuyNowView ()
{
    __weak IBOutlet UILabel *jxzLab;
    __weak IBOutlet UILabel *titleLab;
    __weak IBOutlet UILabel *allCountLab;
    __weak IBOutlet UILabel *ygmLab;
    __weak IBOutlet UILabel *leftLab;
    __weak IBOutlet UILabel *lab;
    __weak IBOutlet UILabel *tsLab;
    
    UIProgressView *progressView;
    
    //记录锁住信息
    NSMutableArray *lockList;
    NSInteger listCount;
}
@end
@implementation BuyNowView

- (void)awakeFromNib
{
    
    if(WYMWITH > 320){
       tsLab.font = [UIFont systemFontOfSize:14];
    }
    jxzLab.textColor = QBB_RED_COLOR;
    jxzLab.layer.borderWidth = 0.5;
    jxzLab.layer.borderColor = QBB_RED_COLOR.CGColor;
    jxzLab.layer.masksToBounds = YES;
    jxzLab.layer.cornerRadius = 2;
    lab.layer.cornerRadius = 2;
    lab.layer.masksToBounds = YES;
    
    //改变进度条的默认高度
    progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    // progressView's frame will be small/standard height
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    progressView.frame = CGRectMake(8*app.autoSizeScaleX, 75, 304*app.autoSizeScaleX, 2);
    progressView.progressTintColor = [UIColor redColor];
    progressView.layer.masksToBounds = YES;
    progressView.layer.cornerRadius = 2;
    //改变进度条的默认高度
    CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 2.8f);
    progressView.transform = transform;
    [self addSubview:progressView];
}


//填充view数据的方法
- (void)fillViewWithDic:(NSDictionary *)dic
{
    titleLab.text = [NSString stringWithFormat:@"(第%@期)%@",dic[@"goods"][@"qishu"],dic[@"goods"][@"title"]];
    allCountLab.text = [NSString stringWithFormat:@"%@次",dic[@"goods"][@"zongrenshu"]];
    NSString*can = dic[@"goods"][@"canyurenshu"];
    ygmLab.text = [NSString stringWithFormat:@"%@次",can];
    leftLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"剩余:  " Middle:dic[@"goods"][@"shenyurenshu"] RightStr:@" 次" Font:15];
    NSString *ygm = dic[@"goods"][@"canyurenshu"];
    NSString *all= dic[@"goods"][@"zongrenshu"];
    progressView.progress = [ygm floatValue]/[all floatValue];
    
    NSString *lockFlag = dic[@"goods"][@"is_locked"];
    if ([lockFlag isEqualToString:@"1"]) {
        NSArray *list = dic[@"goods"][@"locked_list"];
        lockList = [[NSMutableArray alloc]initWithArray:list];
        NSNumber *cn = dic[@"goods"][@"locked_total"];
        listCount = [cn integerValue];
        UIButton *lockBtn = [UIButton buttonWithType:0];
        CGFloat ww = [ygmLab.text sizeWithFont:[UIFont systemFontOfSize:15] maxSize:CGSizeMake(58, 50)].width;
        lockBtn.frame = CGRectMake(CGRectGetMinX(ygmLab.frame)+ww+15, CGRectGetMinY(ygmLab.frame)-2, 26, 26);
        [lockBtn setImage:[UIImage imageNamed:@"icon_lock"] forState:UIControlStateNormal];
        [lockBtn addTarget:self action:@selector(lockbtnOnclick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:lockBtn];
        
        [progressView setProgressTintColor:[UIColor colorWithRed:238/255.0 green:170/255.0 blue:0/2555.0 alpha:1.0]];
        
    }
    else
    {
        [progressView setProgressTintColor:[UIColor redColor]];
    }
}

//锁按钮的点击事件
- (void)lockbtnOnclick
{
    LockView *lockVIew = [[LockView alloc]initWithArr:lockList Count:[NSString stringWithFormat:@"%ld",(unsigned long)listCount]];
    [WINDOW addSubview:lockVIew];
}


@end
